class Resource < ActiveRecord::Base
    belongs_to :site
    validates_presence_of :upload, :title
    file_column :upload
    
    before_validation_on_create :set_title
    before_validation_on_create :delete_similar
    
    def set_title
        self.title = self.upload.split('/').last
    end
    
    def delete_similar
        Resource.delete_all(["site_id = ? AND title = ?", self.site_id, self.title]) 
    end
    
    def get_site_id
        self.site_id.to_s 
    end
    
end